package com.sanpu.kxe.business.card.presenter;

import android.app.Activity;
import android.text.TextUtils;

import com.sanpu.kxe.business.card.bean.BankInfoInput;
import com.sanpu.kxe.business.card.contract.AddBankSecondContract;
import com.sanpu.kxe.business.card.provider.CardOpenProvider;
import com.sanpu.kxe.common.interfaces.CommonConfig;
import com.sanpu.kxe.utils.ToastUtil;
import com.sanpu.kxe.utils.VerifyUtil;

/**
 * Description：添加银行卡第二步
 * Created by 薛勇军 on 2018/7/24.
 */

public class AddBankSecondPresenter implements AddBankSecondContract.Presenter {

    private AddBankSecondContract.View mView;

    private BankInfoInput infoInput = null;

    public AddBankSecondPresenter(AddBankSecondContract.View mView) {
        this.mView = mView;
    }

    @Override
    public void initDataView(BankInfoInput infoInput) {
        this.infoInput = infoInput;
        if (infoInput == null || TextUtils.isEmpty(infoInput.getCardType())) {
            ToastUtil.showTextViewPrompt("暂时不支持该卡");
            ((Activity)mView.getContext()).finish();
            return;
        }
        if (!CommonConfig.DEPOSIT_CARD_TYPE.equals(infoInput.getCardType())
                && !CommonConfig.CREDIT_CARD_TYPE.equals(infoInput.getCardType())) {
            ToastUtil.showTextViewPrompt("暂时不支持该卡");
            ((Activity)mView.getContext()).finish();
            return;
        }
        mView.showBankInfo(infoInput.getBankName());
    }

    @Override
    public void onNextClick(String phoneNumber) {
        if (VerifyUtil.checkPhoneNumber(phoneNumber, true)) {
            return;
        }
        infoInput.setRsdTel(phoneNumber);
        CardOpenProvider.getInstance().openVerificationActivity(mView.getContext(), infoInput);
    }

    @Override
    public void onDestroyPresenter() {
        if (mView != null) {
            mView = null;
        }
    }
}
